﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:COL_MAINCHG
	/// </summary>
	public partial class COL_MAINCHG : BaseDAL<GSLMS.Entity.TB_COL_MAINCHG>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public COL_MAINCHG()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_COL_MAINCHG model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_COLID", model.COLID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_CHGTYPE", model.CHGTYPE),
								new OracleParameter("P_CHGOUTDATE", model.CHGOUTDATE),
								new OracleParameter("P_ACTIONSTATUS", model.ACTIONSTATUS),
								new OracleParameter("P_CHGOUTBY", model.CHGOUTBY),
								new OracleParameter("P_ACTIONBY", model.ACTIONBY),
								new OracleParameter("P_ACTIONDATE", model.ACTIONDATE),
								new OracleParameter("P_CHGINDEP", model.CHGINDEP),
								new OracleParameter("P_CHGINDEPID", model.CHGINDEPID),
								new OracleParameter("P_CHGINNAME", model.CHGINNAME),
								new OracleParameter("P_CHGINUSER", model.CHGINUSER)};
  
			for (int i = 0; i < 20; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_mainchg_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_COL_MAINCHG model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_COLID", model.COLID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_CHGTYPE", model.CHGTYPE),
								new OracleParameter("P_CHGOUTDATE", model.CHGOUTDATE),
								new OracleParameter("P_ACTIONSTATUS", model.ACTIONSTATUS),
								new OracleParameter("P_CHGOUTBY", model.CHGOUTBY),
								new OracleParameter("P_ACTIONBY", model.ACTIONBY),
								new OracleParameter("P_ACTIONDATE", model.ACTIONDATE),
								new OracleParameter("P_CHGINDEP", model.CHGINDEP),
								new OracleParameter("P_CHGINDEPID", model.CHGINDEPID),
								new OracleParameter("P_CHGINNAME", model.CHGINNAME),
								new OracleParameter("P_CHGINUSER", model.CHGINUSER)};
  
			for (int i = 0; i < 20; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_mainchg_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_mainchg_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_COL_MAINCHG DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_COL_MAINCHG model = new GSLMS.Entity.TB_COL_MAINCHG();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["COLID"]!=null && dr["COLID"].ToString()!="")
				{
					model.COLID=OracleHelper.ToLong(dr["COLID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["LOANNO"]!=null && dr["LOANNO"].ToString()!="")
				{
					model.LOANNO=dr["LOANNO"].ToString();
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CUSTNO"]!=null && dr["CUSTNO"].ToString()!="")
				{
					model.CUSTNO=dr["CUSTNO"].ToString();
				}
				if(dr["PRODUCTNAME"]!=null && dr["PRODUCTNAME"].ToString()!="")
				{
					model.PRODUCTNAME=dr["PRODUCTNAME"].ToString();
				}
				if(dr["PRODUCTID"]!=null && dr["PRODUCTID"].ToString()!="")
				{
					model.PRODUCTID=OracleHelper.ToLong(dr["PRODUCTID"].ToString());
				}
				if(dr["CHGTYPE"]!=null && dr["CHGTYPE"].ToString()!="")
				{
                    model.CHGTYPE = OracleHelper.ToInt(dr["CHGTYPE"].ToString());
				}
				if(dr["CHGOUTDATE"]!=null && dr["CHGOUTDATE"].ToString()!="")
				{
					model.CHGOUTDATE=DateTime.Parse(dr["CHGOUTDATE"].ToString());
				}
				if(dr["ACTIONSTATUS"]!=null && dr["ACTIONSTATUS"].ToString()!="")
				{
                    model.ACTIONSTATUS = OracleHelper.ToInt(dr["ACTIONSTATUS"].ToString());
				}
				if(dr["CHGOUTBY"]!=null && dr["CHGOUTBY"].ToString()!="")
				{
					model.CHGOUTBY=dr["CHGOUTBY"].ToString();
				}
				if(dr["ACTIONBY"]!=null && dr["ACTIONBY"].ToString()!="")
				{
					model.ACTIONBY=dr["ACTIONBY"].ToString();
				}
				if(dr["ACTIONDATE"]!=null && dr["ACTIONDATE"].ToString()!="")
				{
					model.ACTIONDATE=DateTime.Parse(dr["ACTIONDATE"].ToString());
				}
				if(dr["CHGINDEP"]!=null && dr["CHGINDEP"].ToString()!="")
				{
					model.CHGINDEP=dr["CHGINDEP"].ToString();
				}
				if(dr["CHGINDEPID"]!=null && dr["CHGINDEPID"].ToString()!="")
				{
					model.CHGINDEPID=OracleHelper.ToLong(dr["CHGINDEPID"].ToString());
				}
				if(dr["CHGINNAME"]!=null && dr["CHGINNAME"].ToString()!="")
				{
					model.CHGINNAME=dr["CHGINNAME"].ToString();
				}
				if(dr["CHGINUSER"]!=null && dr["CHGINUSER"].ToString()!="")
				{
					model.CHGINUSER=dr["CHGINUSER"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_COL_MAINCHG GetByID(long ID)
		{
			GSLMS.Entity.TB_COL_MAINCHG sModel = new GSLMS.Entity.TB_COL_MAINCHG();
			string sql = "";
			sql = "select * from TB_COL_MAINCHG where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_COL_MAINCHG> GetList(GSLMS.Entity.TB_COL_MAINCHG searchParam)
		{
			var list=new List<GSLMS.Entity.TB_COL_MAINCHG>();
			DataTable dt = null;
			string tblName = "TB_COL_MAINCHG";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_COL_MAINCHG model = new GSLMS.Entity.TB_COL_MAINCHG();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

